function selectAreaMap(){
	/*change by hmh*/
	var childId=$("#childId").val();
	//alert(childId);
	var mapFlag=$("#mapFlag").val();
	if(mapFlag=='1'){
		//alert("mapFlag = 1");
		$.get(appPath+"/webarea/findAreaParentId.action?childId="+childId,function(data){
			imgInit2(data);
			},"json");
		$("#mapFlag").val("");
	}
	else{
		//alert("selectednew is empty!");
		$.get(appPath+"/webarea/areaInfoInit.action?id="+Math.random(),function(data){ 		
		    imgInit(data);
		},"json");
	}

};
function imgInit2(data){
	var area=data.areaInfoDto;
	//alert(area.length);

	for(var i=0;i<area.length;i++){
		var childid=area[i].area_id;
	$.get(appPath+"/webarea/findAreaParentId.action?childId="+area[i].parent_id,function(data){
		imgInit3(data);
	},"json");
	}
	
};
function imgInit3(data){
	var area=data.areaInfoDto;
	for(var i=0;i<area.length;i++){
		chooseManage(area[i].area_id,area[i].language_id,area[i].area_img,area[i].parent_id,area[i].name,area[i].coordinate_x,area[i].coordinate_y);
		
	}
	var childId=$("#childId").val();
	//alert(childId);
	$.get(appPath+"/webarea/findAreaParentId.action?childId="+childId,function(data){
		imgInit4(data);
		},"json");
}
function imgInit4(data){
	var area=data.areaInfoDto;
	for(var i=0;i<area.length;i++){
		chooseManage(area[i].area_id,area[i].language_id,'',area[i].parent_id,area[i].name,area[i].coordinate_x,area[i].coordinate_y);
		
	}
	
}

function imgInit(data){

	var area=data.areaInfoDto;
	$("#areaMap").html("");
for(var i=0;i<area.length;i++){
	var x1=area[i].coordinate_x;
	var y1=area[i].coordinate_y;
	var x2=parseInt(x1)+103;
	var y2=parseInt(y1)+27;
$("#areaMap").append("<area shape=\"rect\" coords=\""+x1+","+y1+","+x2+","+y2+"\" href =\"#*\" target=\"_self\" alt=\""+area[i].name+"\"  onfocus=\"this.blur()\" title=\""+area[i].name+"\" id=\""+area[i].area_id+"\" onclick=\"chooseManage('"+area[i].area_id+"','"+area[i].language_id+"','"+area[i].area_img+"','"+area[i].parent_id+"','"+area[i].name+"','"+x1+"','"+y1+"')\"/>");		
}
}


function chooseManage(areaID,languageID,imgID,parentID,name,x1,y1){
	if(imgID=="null"||imgID==""){
		var x=x1+"px";
		var y2=parseInt(y1)+36;
		var y=y2+"px";
		
	    $("#selectedInfo").html("<P>"+name+"</p>");
		$("#selectedInfo p").css({"margin-top": "6px"});
		$("#selectedInfo").css({"width": "103px", "height": "27px","float": "left","background": "#2828FF",
			"position": "relative", "left":""+x+"", top:""+y+"","color": "white", "text-align": "center" ,
			"margin-top": "-35px",
			"border":"0px",
		"border-radius":"5px",
		"-moz-border-radius":"5px",
		"-webkit-border-radius":"5px",
		"-o-border-radius":"5px"	
		});
	
		$("#selectedInfo").show();
		selectArea(areaID,languageID);
       $("#areaName").html("<p class=\"mapbutton\">"+name+"</p>");
		return;
		}
	else{
		
	var imgsrc=$("#areimg").attr("src");
	  var a=imgsrc. lastIndexOf("=");
	  var imgsrc1=imgsrc.substring(0,a+1);
	$("#areimg").attr("src",imgsrc1+imgID);
//$("#areimg").attr("src",appPath+"/images/"+imgID);
    $("#selectedInfo").hide();
	var backtxt="Back at the next higher level map";
	if(languageID=="ja"){
		backtxt="地図上で返す";
	}
	if(languageID=="zh-Hans"){
		backtxt="返回上一级地图";
	}
	$("#backButton").html("<input type=\"button\" id=\"return\" style=\"cursor:pointer\" value=\""+backtxt+"\"  class=\"mapbutton\" onclick=\"backParent('"+parentID+"')\"/>");

	$.get(appPath+"/webarea/areaChoose.action?parent_id="+areaID+"&id="+Math.random(),function(data){ 		
	    imgInit(data);
	},"json");	
	return;
	} 

}
function backParent(parentID){
if(parentID==""||parentID=="null")
{	
	var imgsrc=$("#areimg").attr("src");
	  var a=imgsrc. lastIndexOf("/");
	  var imgsrc1=imgsrc.substring(0,a+1);
	$("#areimg").attr("src",imgsrc1+"world.jpg");
	//$("#areimg").attr("src",appPath+"/images/area/world.jpg");
	
	$("#backButton").html("");
	 $("#selectedInfo").hide();
	$("#areaName").html("");
	selectAreaMap();
	}

else{
	
	$("#selectedInfo").hide();
	$("#areaName").html("");
	$.get(appPath+"/webarea/areaChooseById.action?parent_id="+parentID+"&id="+Math.random(),function(data){ 		
		backpage(data);
	},"json");	

}
}

  function backpage(data){
		var area=data.areaInfoDto;
		chooseManage(area[0].area_id,'',area[0].area_img,area[0].parent_id,'','','');  	
	  
  }
